<template>
  <div class="parent">
    <echartsDom v-if="isShowEcharts" style="width: 100%; height: 100%" :width="width" :height="height" :option="option" :type="type" />
    <div v-else>
      <px-empty :image-size="50" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, ref } from "vue";
import echartsDom from "./echartsDom.vue";
import { queryConsumeChartForDay } from "@/api/waterKanban";
const props = defineProps({
  width: {
    type: String,
    default: ""
  },
  height: {
    type: String,
    default: ""
  },
  color: {
    type: String,
    default: "#3B82F6"
  },
  type: {
    type: String,
    default: ""
  }
});
const isShowEcharts = ref(false);
const state = reactive({
  option: {}
});
const { option } = toRefs(state);

const getoptions = () => {
  queryConsumeChartForDay({ dictKey: "EI01", day: 7 }).then((response: any) => {
    console.log(response);
    isShowEcharts.value = true;
    option.value = {
      backgroundColor: props.type == "dark" ? "#001e3b" : "",
      color: ["#3B82F6", "#FABF2B"],
      grid: {
        left: "10px",
        top: "40px",
        right: "0px",
        bottom: "10px",
        containLabel: true
      },
      legend: {
        data: ["UPW", "WWT"]
      },
      tooltip: {
        trigger: "axis"
      },
      xAxis: {
        type: "category",
        boundarGap: false,
        data: response.xaxis
      },
      yAxis: {
        name: "电耗指标 (KWh)",
        type: "value"
      },
      series: [
        {
          name: "UPW",
          data: response.panelList.filter(item => item.title == "UPW")[0].details.map(item => (item.value != null ? item.value : 0))
            ? response.panelList.filter(item => item.title == "UPW")[0].details.map(item => (item.value != null ? item.value : 0))
            : [0, 0, 0, 0, 0, 0, 0],
          type: "line"
        },
        {
          name: "WWT",
          data: response.panelList.filter(item => item.title == "WWT")[0].details.map(item => (item.value != null ? item.value : 0))
            ? response.panelList.filter(item => item.title == "WWT")[0].details.map(item => (item.value != null ? item.value : 0))
            : [0, 0, 0, 0, 0, 0, 0],
          type: "line"
        }
      ]
    };
  });
};
getoptions();
</script>

<style scoped lang="scss">
.parent {
  float: left;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>
